package leetcode;

import java.util.HashSet;

public class Q0003 {
    public int lengthOfLongestSubstring(String s) {
        int res = 0;
        int i = 0;
        boolean[] cnts = new boolean[128];
        for (int j = 0; j < s.length(); j++) {
            if (cnts[s.charAt(j)]) {
                res = Math.max(res, j - i);
                while (cnts[s.charAt(j)]) {
                    cnts[s.charAt(i++)] = false;
                }
            }
            cnts[s.charAt(j)] = true;
        }
        res = Math.max(res, s.length() - i);
        return res;
    }
}
